package com.zhanqiao.service;

import com.zhanqiao.Dao.PublishContentDao;
import com.zhanqiao.domain.ArticleBean;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class PublishContentService implements ArticleService {
    @Override
    public List<ArticleBean> articleService() {
        return null;
    }

    public int articleService(String title, String content, String publishDate, String state,String tag) {
        ArticleBean articleBean = new ArticleBean();
        articleBean.setUid(5);
        articleBean.setTitle(title);
        articleBean.setContent(content);
        DateFormat df = new SimpleDateFormat("yyyy年MM月dd日HH:mm:ss");
        try {
            Date publishdate = df.parse(publishDate);
            articleBean.setPublishDate(publishdate);
            if(Integer.parseInt(tag)==0){
                articleBean.setTag(false);
            }else{
                articleBean.setTag(true);
            }
            articleBean.setSendstate(state);
            PublishContentDao publishContentDao = new PublishContentDao();
            int i = publishContentDao.insertArticle(articleBean);
            return i;

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
